package com.example.wechattest;

import android.graphics.Color;
import android.os.Bundle;

import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ConnectFragment extends Fragment {

    private LinearLayout ll1;
    private String[] itemTitles = {"新的朋友", "仅聊天的朋友", "群聊", "标签", "公众号"};
    private int[] itemImages = {R.drawable.ic_round_add_person, R.drawable.ic_round_only_friend, R.drawable.ic_round_group_24, R.drawable.ic_round_lable, R.drawable.ic_round_gongzhonghao};
    private String[] itemColors = {"#fb9b3c", "#fb9b3c", "#06bf61", "#247fd2", "#247fd2"};

    private String[][] names = {{"阿富汗", "阿Q", "阿甘", "阿一莫"}, {"比伯", "比例", "比利", "笔试"}, {"楚楚", "阿Q", "曹操", "成龙"}, {"狄仁杰", "董西", "段誉", "杜甫"}};

    public ConnectFragment() {
        // Required empty public constructor
    }


    public static ConnectFragment newInstance(String param1, String param2) {
        ;
        return null;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_connect, container, false);
        ll1 = inflate.findViewById(R.id.ll1);
        initDate();
        return inflate;
    }

    private void initDate() {

        for (int i = 0; i < itemTitles.length; i++) {
            View content = getLayoutInflater().inflate(R.layout.connect_item, null);
            CardView cardView = content.findViewById(R.id.content_cv);
            ImageView imageView = cardView.findViewById(R.id.content_iv);
            TextView textView = content.findViewById(R.id.content_tv);
//            cardView.setBackgroundColor(Color.parseColor(itemColors[i]));
//            imageView.setImageDrawable(getResources().getDrawable(itemImages[i]));
            imageView.setImageDrawable(getResources().getDrawable(itemImages[i]));
            imageView.setBackgroundColor(Color.parseColor(itemColors[i]));
            textView.setText(itemTitles[i]);
            ll1.addView(content);
        }

        for (int i = 'a'; i < 'e'; i++) {
            View inflate = getLayoutInflater().inflate(R.layout.connect_item_font, null);
            TextView zimu = inflate.findViewById(R.id.connect_item_font);
            char c = (char) i;
            zimu.setText(String.valueOf(c));
            ll1.addView(inflate);
            //加载用户卡片
            for (int k = 0; k < 4; k++) {
                View content = getLayoutInflater().inflate(R.layout.connect_item2, null);
                ImageView imageView = content.findViewById(R.id.content_iv);
                TextView textView = content.findViewById(R.id.content_tv);
                imageView.setBackground(getResources().getDrawable(R.drawable.l));
                Log.i("TAG", "initDate: " + i + "  " + (i-97));
                textView.setText(names[i-97][k]);
                ll1.addView(content);
            }
        }

    }
}